import { Injectable } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { Observable } from 'rxjs';
import { DataSeriesDTO } from 'src/app/project/model/icm/dashboard/data-series.dto';
import { ApiPagedData } from 'src/app/project/model/common/api-paged-data';
import { ConsolidatedResultsDTO } from 'src/app/project/model/icm/icm-student-academic/consolidated-results/consolidated-results.dto';
import { QueryOptions } from 'src/app/project/model/common/query-options';

@Injectable({
  providedIn: 'root',
})
export class StatisticalAnalysisService {
  private static URL = '/api/icm-statistical-analysis';

  constructor(private http: _HttpClient) {}

  /**
   * 分页查询综合成绩
   * @param option 分页参数
   * @param academyId 学院名称
   * @param professionId 专业名称
   * @param classId 班级名称
   * @param studentName 学生名称
   * @param year 测评年份
   */
  findOnePage(
    option: QueryOptions,
    academyId?: string,
    professionId?: string,
    classId?: string,
    studentName?: string,
    year?: string,
  ): Observable<ApiPagedData<ConsolidatedResultsDTO>> {
    const params = {};
    Object.assign(
      params,
      option,
      academyId ? { academyId } : {},
      professionId ? { professionId } : {},
      classId ? { classId } : {},
      studentName ? { studentName } : {},
      year ? { year } : {},
    );
    return this.http.get<ApiPagedData<ConsolidatedResultsDTO>>(StatisticalAnalysisService.URL, params);
  }

  /**
   * 统计分析学生综合成绩情况
   *
   * @param year 测评年份
   * @param standard 达标分数
   * @param notStandard 未达标分数
   * @param earlyWarningDown 预警下限
   * @param earlyWarningUp 预警上限
   * @param academyId 学院名称
   * @param professionId 专业名称
   * @param classId 班级名称
   */
  consolidatedResultsCount(
    year: string,
    standard: number,
    notStandard: number,
    earlyWarningDown: number,
    earlyWarningUp: number,
    academyId?: string,
    professionId?: string,
    classId?: string,
  ): Observable<Array<DataSeriesDTO>> {
    const params = {};
    Object.assign(
      params,
      year ? { year } : {},
      standard ? { standard } : {},
      notStandard ? { notStandard } : {},
      earlyWarningDown ? { earlyWarningDown } : {},
      earlyWarningUp ? { earlyWarningUp } : {},
      academyId ? { academyId } : {},
      professionId ? { professionId } : {},
      classId ? { classId } : {},
    );
    return this.http.get<Array<DataSeriesDTO>>(`${StatisticalAnalysisService.URL}/consolidated-results/count`, params);
  }

  /**
   * 统计分析学生学业进展情况
   *
   * @param standard 达标分数
   * @param notStandard 未达标分数
   * @param earlyWarningDown 预警下限
   * @param earlyWarningUp 预警上限
   * @param academyId 学院名称
   * @param professionId 专业名称
   * @param classId 班级名称
   * @param grade 所属年级
   */
  graduationCreditCount(
    standard: number,
    notStandard: number,
    earlyWarningDown: number,
    earlyWarningUp: number,
    academyId?: string,
    professionId?: string,
    classId?: string,
    grade?: string,
  ): Observable<Array<DataSeriesDTO>> {
    const params = {};
    Object.assign(
      params,
      grade ? { grade } : {},
      standard ? { standard } : {},
      notStandard ? { notStandard } : {},
      earlyWarningDown ? { earlyWarningDown } : {},
      earlyWarningUp ? { earlyWarningUp } : {},
      academyId ? { academyId } : {},
      professionId ? { professionId } : {},
      classId ? { classId } : {},
    );
    return this.http.get<Array<DataSeriesDTO>>(`${StatisticalAnalysisService.URL}/graduation-credits/count`, params);
  }
}
